const inputEl = document.querySelector("input");
const cancelEl = document.querySelector("#cancel");
let counter = 0;
const inputChange = throttle(
  function () {
    console.log(`发送了${++counter}次网络请求`, this);
    return "11111111";
  },
  2000,
  {
    leading: false,
    trailing: true,
    resultCallback: function (res) {
      console.log(res);
    },
  }
);

inputEl.oninput = inputChange;

cancelEl.addEventListener("click", function () {
  inputChange.cancel();
});
